<template>
  <div class="content">
    <Button type="primary" @click="creatActivity" v-if="unlocking('0107110101')">新建活动</Button>
    <Button type="primary" style="margin-left: 10px">
      <a
        href="https://images.tospurfang.com/doc/%E6%8A%BD%E5%A5%96%E6%B4%BB%E5%8A%A8%E6%93%8D%E4%BD%9C%E6%89%8B%E5%86%8C.pdf"
        style="color: #fff"
        target="_blank">
        查看操作指引
      </a>
    </Button>

    <dt-grid ref="table" :columns="columns" :page="page" :onFetch="onFetch" />
    <create-activity ref="creatActivity"></create-activity>
    <release-model ref="releaseModel"></release-model>
  </div>
</template>

<script>
  import createActivity from './components/createActivity.vue'
  import releaseModel from './components/releaseModel.vue'
  import activityMgr from '@/biz/activity/activity'
  import columnOpt from './opt/activityColumn'
  export default {
    components: {
      createActivity,
      releaseModel
    },
    data() {
      return {
        creatActivityFlag: false,
        columns: [],
        page: {
          total: 0,
          current: 1
        }
      }
    },
    mounted() {
      this.$refs.table.init(this, new columnOpt(this))
      this.$refs.table.fetch()
    },
    created() {},
    methods: {
      delActivity(val) {
        this.$Modal.confirm({
          title: '删除',
          content: '<p>确认删除该活动？</p>',
          onOk: () => {
            let params = {
              acId: val.acId,
              type: 'del'
            }
            activityMgr.endBasics(params).then((res) => {
              this.$Message.success('删除成功。')
              this.$refs.table.fetch()
            })
          },
          onCancel: () => {}
        })
      },
      closeActivity(val) {
        this.$Modal.confirm({
          title: '关闭',
          content: '<p>是否强制结束该活动？强制结束后，该活动不可再度启用</p>',
          onOk: () => {
            let params = {
              acId: val.acId,
              type: 'end'
            }
            activityMgr.endBasics(params).then((res) => {
              this.$Message.success('强制结束成功。')
              this.$refs.table.fetch()
            })
          }
        })
      },
      getActivityData(val) {
        this.$router.push({
          path: '/marketingCenter/activityManagement/activityData',
          query: {
            acId: val.acId
          }
        })
      },
      creatActivity() {
        this.$refs.creatActivity.show()
      },
      // 列表数据
      onFetch(data) {
        this.paramsAll = data
        this.paramsAll.housesId = this.$dt.buildInfo().housesId
        return activityMgr
          .basicsList(this.paramsAll)
          .then((res) => {
            this.page.total = res.total
            return res.list
          })
          .catch((err) => {
            this.total = 0
          })
      },
      // 列表操作
      delFun(val) {
        this.$Modal.confirm({
          title: '删除',
          content: '<p>删除后，该顾问将无法接到楼盘呼入电话及TA的隐私号将被释放，是否确认删除？</p>',
          onOk: () => {
            //  承接人删除接口
            receiverMgr.receiverDel({ receiverId: val.id }).then((res) => {
              this.$Message.success('承接人删除成功。')
              setTimeout(() => {
                this.$refs.table.fetch()
              }, 1000)
            })
          },
          onCancel: () => {}
        })
      },
      checkFun(val) {
        let dataVal = {
          acId: val.acId,
          name: val.name,
          status: val.status,
          btnFlag: 'flag',
          promoteSn: val.promoteSn
        }
        this.$refs.releaseModel.show(dataVal)
      },
      editFun(val) {
        this.$router.push({
          path: '/marketingCenter/activityManagement/addEditActivity',
          query: {
            acId: val.acId
          }
        })
      },
      setRecevier() {
        this.$refs.addReceiver.show(this.noReceiverCase)
      },
      onReset() {},
      //拓客码
      expandFun(row) {
        let data = {
          activityId: row.acId,
          activityName: row.name
        }
        this.$router.push({
          path: '/marketingCenter/expandCodeDetail',
          query: {
            ...data,
            parentPath: '/marketingCenter/activityManagement/activity',
            formPath: 'activity'
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    padding: 20px;
  }
</style>
